﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;

namespace STT.Business
{
    public class BTbPhongHoc
    {
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbPhongHoc_SelectAll", null);
            return all;
        }
        public static DataTable SelectAll1()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbPhongHoc_SelectAll1", null);
            return all;
        }
        //-----------------------------------------------------------//
        public static void Insert(ETbPhongHoc OTbPhongHoc)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenPH", OTbPhongHoc.TenPhongHoc);
            pr[1] = new SqlParameter(@"TrangThai", OTbPhongHoc.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbPhongHoc_Insert", pr);
        }
        //-----------------------------------------------------------//
        public static void Update(ETbPhongHoc OTbPhongHoc)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaPH", OTbPhongHoc.MaPhongHoc);
            pr[1] = new SqlParameter(@"TenPH", OTbPhongHoc.TenPhongHoc);
            pr[2] = new SqlParameter(@"TrangThai", OTbPhongHoc.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbPhongHoc_Update", pr);
        }
        //-----------------------------------------------------------//
        public static void Delete(int MaPhongHoc)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaPH", MaPhongHoc);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbPhongHoc_Delete", pr);
        }
        //-----------------------------------------------------------//

        public static bool KiemTraDuLieu_Sua(ETbPhongHoc PhongHoc)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenPH", PhongHoc.TenPhongHoc);
            pr[1] = new SqlParameter(@"MaPH", PhongHoc.MaPhongHoc);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbPhongHoc_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//

        public static bool KiemTraDuLieu(ETbPhongHoc PhongHoc)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenPH", PhongHoc.TenPhongHoc);
           
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbPhongHoc_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        public static bool KiemTraMaPhongHoc(ETbPhongHoc PhongHoc)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaPH", PhongHoc.MaPhongHoc);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbPhongHoc_KiemTraMaPhongHoc", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static DataTable SearchPhongHoc(ETbPhongHoc PhongHoc)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenPH", PhongHoc.TenPhongHoc);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbPhongHoc_Search", pr);
            return all;
        }
        //-----------------------------------------------------------//
    }
}